{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "688460b9-9324-43f7-ae6d-bc36cc62ff8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from IPython import display\n",
    "from d2l import torch as d2l\n",
    "\n",
    "batch_size = 256\n",
    "train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size)\n",
    "if torch.cuda.is_available():\n",
    "    print('Current device:', torch.cuda.current_device())\n",
    "    print('Device name:', torch.cuda.get_device_name(0))\n",
    "    # 设置多个可用GPU时，将索引从0开始设置\n",
    "else:\n",
    "    print('Using CPU!')\n",
    "\n",
    "# 如果需要指定显卡：\n",
    "torch.cuda.set_device(0)  # 替换为要使用的GPU索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9dfc6d8d-45f2-451d-af84-5a7edecaaef9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (pytorch_env)",
   "language": "python",
   "name": "pytorch_env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
